package com.kaola.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;

import com.kaola.dao.UserProductDAO;
import com.kaola.pojo.User;
import com.kaola.pojo.UserProduct;

public class UserProductDAOImpl extends HibernateTemplate implements UserProductDAO {

	public void add(UserProduct userProduct) {
		save(userProduct);
	}

	public UserProduct get(int uid, int pid) {
		List<UserProduct> ups = find("from UserProduct up where up.user.id=? and up.product.id=?", uid, pid);
		UserProduct up = null;
		if (ups.size() > 0) {
			up = ups.get(0);
		}
		return up;
	}
	
	public UserProduct get(int upid) {
		return get(UserProduct.class, upid);
	}
	
	public List<UserProduct> list(User user) {
		return find("from UserProduct up where up.user=?", user);
	}

	public void modify(UserProduct userProduct) {
		update(userProduct);
	}

	public void delete(int upid) {
		delete(get(UserProduct.class, upid));
	}
}
